﻿using System;
using System.Collections.Generic;
using System.Text;
using Watchdog.Bll.Factory;

namespace Watchdog.Bll.Base {

    public partial class TestUnitBase {

        #region [ Local variables ]
        Facade.TestUnit intdata;
        #endregion

        #region [ Constructor(s) ]
        internal TestUnitBase () {
            intdata = new Watchdog.Facade.TestUnit ();
        }
        internal TestUnitBase (Facade.TestUnit testunit) : base () {
            intdata = testunit;
        }
        #endregion

        #region [ Field Properties ]
        public int Id {
            get { return intdata.Id; }
        }
        public virtual string Name {
            get { return intdata.Name; }
            set { intdata.Name = value; }
        }
        public virtual int Zone {
            get { return intdata.Zone; }
            set { intdata.Zone = value; }
        }               
		#endregion
		
        #region [ Data Methods ]
        public void Update () {
            if (Id == 0)
                TestUnitFactory.Insert ( this );
            else
                TestUnitFactory.Update ( this );
        }

        public void Delete () {
            TestUnitFactory.Delete ( this );
        }
        #endregion
		
        internal Facade.TestUnit IntData {
            get { return intdata; }
            set { intdata = value; }
        }

        #region [ Equality ]
        public override int GetHashCode () {
            return Id;
        }
        public static bool operator == ( TestUnitBase lt1, TestUnitBase lt2 ) {
            if (System.Object.ReferenceEquals ( lt1, lt2 ))
                return true;

            if ((object)lt1 == null || (object)lt2 == null)
                return false;
            return lt1.Equals ( lt2 );
        }
        public static bool operator != ( TestUnitBase lt1, TestUnitBase lt2 ) {
            if (lt1 == null || lt2 == null)
                return false;
            return !(lt1 == lt2);
        }

        public override bool Equals ( object obj ) {
            if (!(obj is TestUnitBase))
                return false;
            return (this.CompareTo ( obj ) == 0);
        }

        private int CompareTo ( object obj ) {
            if (!(obj is TestUnitBase)) {
                throw new ArgumentException ( "A 'TestUnitBase' object is required for comparison." );
            }
            return this.Id.CompareTo ( ((TestUnitBase)obj).Id );
        }
        #endregion

	}
}
